{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f74df50b",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install openai"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0d75715c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(api_key = \"<your-open-ai-api-key-here>\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "10a1cb27",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " are an important part of\n"
     ]
    }
   ],
   "source": [
    "prompt = \"They\"\n",
    "\n",
    "\n",
    "response = client.chat.completions.create(\n",
    "  model=\"gpt-3.5-turbo-instruct\",\n",
    "  response_format={ \"type\": \"json_object\" },\n",
    "  messages=[\n",
    "    {\"role\": \"user\", \"content\": prompt}\n",
    "  ],\n",
    "  temperature=0.5,\n",
    "  max_tokens=5,\n",
    "  top_p=1.0,\n",
    "  frequency_penalty=0.0,\n",
    "  presence_penalty=0.0\n",
    ")\n",
    "\n",
    "\n",
    "print(response.choices[0].message.content)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "3c10c706",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "They always say\n",
      "\n",
      "That life is a mystery\n",
      "\n",
      "And we will never really know\n",
      "\n",
      "What happens after we die\n",
      "\n",
      "But I think\n",
      "\n",
      "That we can be pretty sure\n",
      "\n",
      "That there is something\n",
      "\n",
      "After this life\n",
      "\n",
      "Something better\n",
      "\n",
      "And we will finally be able\n",
      "\n",
      "To rest in peace\n"
     ]
    }
   ],
   "source": [
    "prompt = \"Write a poem starting with they\"\n",
    "\n",
    "response = client.chat.completions.create(\n",
    "  model=\"gpt-3.5-turbo-instruct\",\n",
    "  response_format={ \"type\": \"json_object\" },\n",
    "  messages=[\n",
    "    {\"role\": \"user\", \"content\": prompt}\n",
    "  ],\n",
    "  temperature=0.5,\n",
    "  max_tokens=100,\n",
    "  top_p=1.0,\n",
    ")\n",
    "\n",
    "print(response.choices[0].message.content)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1991c344",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
